<?php

/**
 * @Author: zhibinm (113664000@qq.com)
 * @Date:   2018-04-20 15:25:48 
 * @Copyright:   xuebingsi
 * @Last Modified by:   Zhibinm
 * @Last Modified time: 2018-04-20 16:05:04
 */
//------------------------
// PICMS 助手函数
//-------------------------

use think\Cache;
use think\Config;
use think\Cookie;
use think\Db;
use think\Debug;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\Lang;
use think\Loader;
use think\Log;
use think\Model;
use think\Request;
use think\Response;
use think\Session;
use think\Url;
use think\View;
use think\Route;

//设置插件入口路由
Route::any('addons/[:_addons]/[:_controller]/[:_action]', "\\picms\\controller\\Addons@index");

/**
 * [picms_is_install 判断当前cms是否安装]
 * @return [type] [description]
 */
function picms_is_install()
{
	static $picmsIsInstalled;
    if (empty($picmsIsInstalled)) {
        $picmsIsInstalled = file_exists(ROOT_PATH. 'data/install.lock');
    }
    return $picmsIsInstalled;
}

/**
 * 获取网站根目录
 * @return string 网站根目录
 */
function picms_get_root()
{
    $request = Request::instance();
    $root    = $request->root();
    $root    = str_replace('/index.php', '', $root);
    return $root;
}

function picms_url($url = '', $vars = '', $suffix = true, $domain = false)
{
    return Url::build($url, $vars, $suffix, $domain);
}
/**
 * [picms_md5 picms加密]
 * @param  [type] $pw       [description]
 * @param  string $authCode [description]
 * @return [type]           [description]
 */
function picms_md5($pw, $authCode = '')
{
    if (empty($authCode)) {
        $authCode = Config::get('picms.md5_str');
    }
    $result = md5(md5($authCode . $pw));
    return $result;
}
/**
 * [picms_get_client_ip 获取客户端ip]
 * @param  integer $type [description]
 * @param  boolean $adv  [description]
 * @return [type]        [description]
 */
function picms_get_client_ip($type = 0, $adv = false)
{
    return request()->ip($type, $adv);
}

/**
 * 添加钩子
 * @param string $hook 钩子名称
 * @param mixed $params 传入参数
 * @param mixed $extra 额外参数
 * @return void
 */
function hook($hook, &$params = null, $extra = null)
{
    return \think\Hook::listen($hook, $params, $extra);
}